import { SVGUnitParserFactory } from './svgunitparserfactory.js';

class SvgSymbolParser {
    constructor() {
        this.unitList = [];
    }
    parse(mainEle) {
        this.unitList = [];
        let childEles = mainEle.children;
        if (childEles.length < 1) {
            return null;
        }

        let symbol = { id: '', name: '', units: [] };
        const attributes = mainEle.attributes;
        for (let i = 0; i < attributes.length; i++) {
            const attr = attributes[i];
            if (attr.name == 'id') {
                symbol.id = attr.value;
                symbol.name = attr.value;
            }
        }

        for (let i = 0; i < childEles.length; i++) {
            const childEle = childEles[i];
            let tagName = childEle.tagName;
            let result = SVGUnitParserFactory.parse(childEle,true);
            if (result) {
                symbol.units.push(result);
            }
        }
        return symbol;
    }
}


export { SvgSymbolParser }